package actions;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import javax.servlet.http.HttpServletRequest;

import metier.IMetier;

import beans.ClientAdresseBean;

public class ActionVoirPageCreerCompte extends UnicastRemoteObject implements IAction {
	private static final long serialVersionUID = 4294376897581115707L;

	public ActionVoirPageCreerCompte() throws RemoteException {
		super();
	}

	@Override
	public String execute(HttpServletRequest req) throws Exception {
		// TODO Auto-generated method stub
		if(req.getParameter("boolCree") != null){
			ClientAdresseBean client = new ClientAdresseBean(req.getParameter("nom"),req.getParameter("prenom"),req.getParameter("mail"),req.getParameter("motdepasse"),req.getParameter("motdepasse2"),req.getParameter("num"),req.getParameter("rue"),req.getParameter("cp"),req.getParameter("ville"));
			req.setAttribute("client", client);
			boolean err = client.valider();
			if(!err){
				return "pageCreerCompte.jsp";
			}else{
				IMetier metier=(IMetier)Naming.lookup("rmi://localhost:2000/ServeurMetier");
				metier.creerCompte(req.getParameter("nom"),req.getParameter("prenom"),req.getParameter("mail"),req.getParameter("motdepasse"),req.getParameter("num"),req.getParameter("rue"),req.getParameter("cp"),req.getParameter("ville"));
				req.setAttribute("compteCree","true");
				return "pageCreerCompte.jsp";
			}
		}
		return "pageCreerCompte.jsp";
	}

}
